﻿<script>
	$(function() {
		$( "#txtNgaythanhlap" ).datepicker({dateFormat: 'dd-mm-yy'});
		$("#cboCountry").change(function() { 
		/* do something here */ 
			var ajax_url = '../incs/list_school_by_country_id.php?qg_id='+ $("#cboCountry").val();
			$.get(ajax_url,function(data){
			$('#cboSchool').html(data);
			});
		});
	});
</script>
<?php
if (!defined('WEB_ROOT')) {
	exit;
}

// make sure matg exists
if (isset($_GET['id']) && $_GET['id'] > 0) {
	$id = (int)$_GET['id'];
} else {
	// redirect to index.php 
	header('Location: index.php');
}
if (isset($_GET['truong_id']) && $_GET['truong_id'] > 0) {
	$truong_id = (int)$_GET['truong_id'];
}
if (isset($_GET['qg_id']) && $_GET['qg_id'] > 0) {
	$qg_id = (int)$_GET['qg_id'];
}
// Lấy thông tin trường
$sql = "SELECT dv.id, dv.madv, dv.tendv, dv.dienthoai_dv, dv.diadiem, dv.ngaythanhlap, dv.truong_id, qg_id, tenqg
        FROM donvi dv join quocgia qg on dv.qg_id = qg.id
		WHERE dv.id = $id and dv.truong_id is NULL and dv.hieu_luc > 0
		ORDER BY dv.id desc";
		
	$result = mysql_query($sql) or die('Cannot get School. ' . mysql_error());
	$row    = mysql_fetch_assoc($result);
	extract($row);
	
	//combo quốc gia
	$sql = "SELECT id, tenqg
				FROM quocgia
				ORDER BY id";
		$result = dbQuery($sql) or die('Không lấy được thông tin quốc gia. ' . mysql_error());
		
		$countries = array();
		$list = '';
		while($row = dbFetchArray($result)) {
			list($id_qg, $name) = $row;
			$list .= "<option value=\"$id_qg\"";
				if ($id_qg == $qg_id) {
					$list.= " selected";
				}
				$list .= ">$name</option>\r\n";
		}
?> 
<div class="onecolumn">
	<div class="header">
		<span>Sửa thông tin trường</span>
	</div>
	<br class="clear"/>
	<div class="content">
			<form action="processSchool.php?action=modifySchool&id=<?php echo $id; ?>" method="post" enctype="multipart/form-data" name="frmAddSchool" id="frmAddSchool">
			 <table width="100%" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable">
			  <tr> 
				   <td width="150" class="label">Mã trường <span  class="dau*">(*)</span></td>
				   <td class="content"> <input name="txtMadv" type="text" class="box" id="txtMadv" readonly="true" style="background-color:#DADADA" value="<?php echo $madv; ?>"  size="20" maxlength="20"></td>
			  </tr>
			  <tr> 
				   <td width="150" class="label">Tên trường <span  class="dau*">(*)</span></td>
				   <td class="content"> <input name="txtTendv" type="text" class="box" id="txtTendv" value="<?php echo $tendv; ?>"  size="40" maxlength="40"></td>
			  </tr>
			   <tr> 
				   <td width="150" class="label">Điện thoại trường</td>
				   <td class="content"> <input name="txtDienthoai_dv" type="text" class="box" id="txtDienthoai_dv" value="<?php echo $dienthoai_dv; ?>"  size="40" maxlength="40"></td>
			  </tr>
			  <tr> 
				   <td width="150" class="label">Địa điểm</td>
				   <td class="content"> <input name="txtDiadiem" type="text" class="box" id="txtDiadiem" value="<?php echo $diadiem; ?>"  size="40" maxlength="40"></td>
			  </tr>
			  <tr> 
				   <td width="110" class="label">Quốc gia</td>
				   <td class="content"> <select name="cboCountry" id="cboCountry" class="box">
						<option value="" selected>-- Chọn quốc gia --</option>
							<?php
								echo $list;
							?>	 
						</select>  
			  </tr>
			  <tr> 
				   <td width="150" class="label">Ngày thành lập trường</td>
				   <td class="content"><input name="txtNgaythanhlap" type="text" id="txtNgaythanhlap" value="<?php echo $ngaythanhlap; ?>" size="40" maxlength="40" class="box"> </td>
			  </tr>
			
			 </table>
			 <p align="center"> 
			  <input name="btnModifySchool" type="button" id="btnModifySchool" value="Lưu thay đổi" onClick="checkAddSchoolForm();" class="box">
			  &nbsp;&nbsp;<input name="btnCancel" type="button" id="btnCancel" value="  Hủy  " onClick="window.location.href='index.php';" class="box">  
			 </p>
			</form>
		</div>
	</div>